import axios from '@/utils/axios.js'

const createRequest = (url, method) => {
  return (params) => {
    if (method === 'get') {
      return axios.get(url, {params: params})
    } else if (method === 'delete') {
      return axios.delete(url, {data: params})
    } else {
      return axios[method](url, params)
    }
  }
}

const createApiRequests = (endpoints, pre) => {
  const apiRequests = {}
  Object.entries(endpoints).forEach(([key, value]) => {
    apiRequests[key] = createRequest(pre + key, value)
  })
  return apiRequests
}

export default createApiRequests;
